package hu.radai.jsfportal.taglib;

import java.util.Map;

import javax.faces.component.FacesComponent;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;

@FacesComponent(value = "DemoMenu")
public class UIMenu extends UIOutput {

	enum KEYS {
		lang,
		menu
	}
	
	private String lang;
	private Map<String, String> menu;
	
	public String getLang() {
		return lang;
	}
	
	public void setLang(String lang) {
		this.lang = lang;
	}
    
    public Map<String, String> getMenu() {
    	if (menu != null)
    		return menu;
    	return (Map<String, String>) getStateHelper().eval(KEYS.menu);
	}
    
    public void setMenu(Map<String, String> menu) {
		this.menu = menu;
	}
    
    @Override
    public String getFamily() {
    	return ("Menu");
    }
    
    @Override
    public Object saveState(FacesContext context) {
        Object[] values = new Object[3];
        values[0] = super.saveState(context);
        values[1] = lang;
        values[2] = menu;
        return (values);
    }

    @Override
    public void restoreState(FacesContext context, Object state) {
        Object[] values = (Object[]) state;
        super.restoreState(context, values[0]);
        lang = (String) values[1];
        menu = (Map<String, String>) values[2];
    }
}
